<template>
  <div class="barChart"></div>
</template>

<script>
export default {
  props: ["config"],
  name: "",
  data() {
    return {};
  },
  methods: {
    setChart() {
      let option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          backgroundColor: "rgba(11, 41, 116, 0.2)",
          borderColor: "rgba(11, 41, 116, 0.2)",
          textStyle: {
            color: "#fff",
          },
        },
        legend: {
          right: "5% ",
          top: "10%",
          itemGap: 20,
          itemWidth: 14,
          itemHeight: 14,
          textStyle: {
            color: "#fff",
            fontSize: 12,
          },
        },
        textStyle: {
          color: "#fff",
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        color: ["#FFC328", "#5AD8A6", "#2391FF"],
        xAxis: [
          {
            type: "category",
            data: this.config.xdata,
            axisLabel: {
              color: "#D6E1FF",
              fontSize: 12,
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              show: false,
            },
            axisLine: {
              show: false,
            },
          },
        ],
        yAxis: [
          {
            name: "单位：次",
            type: "value",
            axisLabel: {
              color: "#D6E1FF",
              fontSize: 12,
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              show: true,
              lineStyle: {
                type: "dashed",
                color: "#9EA3B4",
                opacity: 0.1,
              },
            },
            axisLine: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: this.config.data.series[0].name,
            type: "bar",
            stack: "user",
            itemStyle: {
              normal: {
                barBorderRadius: [0, 0, 0, 0],
              },
            },
            emphasis: {
              focus: "series",
            },
            barWidth: 20,
            data: this.config.data.series[0].data,
          },
          {
            name: this.config.data.series[1].name,
            type: "bar",
            stack: "user",
            itemStyle: {
              normal: {
                barBorderRadius: [0, 0, 0, 0],
              },
            },
            emphasis: {
              focus: "series",
            },
            barWidth: 20,
            data: this.config.data.series[1].data,
          },
          {
            name: this.config.data.series[2].name,
            type: "bar",
            stack: "user",
            itemStyle: {
              normal: {
                barBorderRadius: [0, 0, 0, 0],
              },
            },
            emphasis: {
              focus: "series",
            },
            barWidth: 20,
            data: this.config.data.series[2].data,
          },
        ],
      };
      let myChart = this.$echarts(this.$el);

      myChart.clear();
      myChart.resize();
      myChart.setOption(option);
    },
  },
  mounted() {
    this.setChart();
  },
};
</script>

<style lang="less" scoped>
.barChart {
  width: 100%;
  margin-top: 1%;
  height: 83%;
}
</style>
